home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / 3DTOSHI2.ZIP / mpg3d / source / g3dworld.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-29  |  3.7 KB  |  138 lines

  1.  
  2. // g3dworld.cpp
  3. //
  4. // Copyright (c) 1996 by Toshiaki Tsuji, all rights reserved.
  5.  
  6. #include "stdgfx.h"
  7. #include "g3dworld.h"
  8.  
  9. G3DWORLD::G3DWORLD ()
  10.   {
  11.     ObjectList = new LINKEDLIST<G3DOBJECT*> (); 
  12.   } // End of Constructor for G3DWORLD
  13.  
  14. G3DWORLD::~G3DWORLD ()
  15.   {
  16.     if (ObjectList!=NULL)
  17.                         { 
  18.                                 ObjectList->ClearAllNode ();
  19.         delete ObjectList;
  20.       } // End if
  21.     ObjectList = NULL;  
  22.   } // End of Destructor for G3DWORLD
  23.  
  24. BOOLEAN G3DWORLD::AddObject ( G3DOBJECT * NewObject )
  25.   {
  26.     ObjectList->AddObject ( NewObject );  
  27.     return TRUE;  
  28.   } // End of AddObject for G3DWORLD
  29.  
  30. VOID G3DWORLD::TransformWorldToCamera ( G3DMATRIX CameraMatrix,
  31.                                         CAMERADATA *CameraData )
  32.   {
  33.     LISTOBJECT<G3DOBJECT*> *ObjectNode;
  34.     G3DOBJECT* Object;
  35.  
  36.     ObjectNode = ObjectList->GetHead ();
  37.  
  38.     while (ObjectNode!=NULL)
  39.       {
  40.         Object = ObjectNode->Data;
  41.         Object->TransformWorldToCamera ( CameraMatrix, CameraData );
  42.         ObjectNode= ObjectNode->NextObject;  
  43.       } // End while 
  44.   } // End of TransformWorldToCamera for G3DWORLD
  45.  
  46. BOOLEAN G3DWORLD::Init ()
  47.   {
  48.     LISTOBJECT<G3DOBJECT*> *ObjectNode;
  49.     G3DOBJECT* Object;
  50.     G3DMATRIX Matrix;
  51.  
  52.     ObjectNode = ObjectList->GetHead ();
  53.  
  54.     InitMatrix ( Matrix );
  55.     
  56.     while (ObjectNode!=NULL)
  57.       {
  58.         Object = ObjectNode->Data;
  59.         Object->Init ();
  60.         Object->TransformLocalToWorld ( Matrix );
  61.         Object->ComputeRadius ();
  62.         ObjectNode= ObjectNode->NextObject;  
  63.       } // End while
  64.     return TRUE;  
  65.   } // End of Init for G3DWORLD
  66.  
  67. G3DOBJECT* G3DWORLD::FindObjectByName ( STRING SearchName )
  68.   {
  69.     LISTOBJECT<G3DOBJECT*> *ObjectNode;
  70.     G3DOBJECT* Object;
  71.  
  72.     ObjectNode = ObjectList->GetHead ();
  73.  
  74.     while (ObjectNode!=NULL)
  75.       {
  76.         Object = ObjectNode->Data->FindObjectByName ( SearchName );
  77.         if (Object!=NULL)
  78.           return Object;
  79.         ObjectNode= ObjectNode->NextObject;  
  80.       } // End while
  81.     return NULL;        
  82.   } // End of FindObjectByName for G3DWORLD
  83.  
  84. G3DOBJECT* G3DWORLD::FindObjectByID ( LONG SearchID )
  85.   {
  86.     LISTOBJECT<G3DOBJECT*> *ObjectNode;
  87.     G3DOBJECT* Object;
  88.  
  89.     ObjectNode = ObjectList->GetHead ();
  90.  
  91.     while (ObjectNode!=NULL)
  92.       {
  93.         Object = ObjectNode->Data->FindObjectByID ( SearchID );
  94.         if (Object!=NULL)
  95.           return Object;
  96.         ObjectNode= ObjectNode->NextObject;  
  97.       } // End while
  98.     return NULL;        
  99.   } // End of FindObjectByID for G3DWORLD
  100.  
  101. LONG G3DWORLD::CountNumShapes ()
  102.   {
  103.     LISTOBJECT<G3DOBJECT*> *ObjectNode;
  104.     LONG Count;
  105.  
  106.     Count = 0;
  107.     
  108.     ObjectNode = ObjectList->GetHead ();
  109.  
  110.     while (ObjectNode!=NULL)
  111.       {
  112.         ObjectNode->Data->CountNumShapes ( &Count );
  113.         ObjectNode= ObjectNode->NextObject;  
  114.       } // End while
  115.     return Count;              
  116.   } // End of CountNumShapes for G3DWORLD
  117.  
  118. LONG G3DWORLD::CheckCollision ( FLPVECTOR3D StartPt, FLPVECTOR3D EndPt,
  119.                                 COLLIDEDATA *CollideList, LONG MaxNum,
  120.                                 float CollideDist, float Gap )
  121.   {
  122.     LISTOBJECT<G3DOBJECT*> *ObjectNode;
  123.     LONG Count;
  124.  
  125.     Count = 0;
  126.     
  127.     ObjectNode = ObjectList->GetHead ();
  128.  
  129.     while (ObjectNode!=NULL)
  130.       {
  131.         ObjectNode->Data->CheckCollision ( StartPt, EndPt, CollideList, &Count,
  132.                                            MaxNum, CollideDist, Gap );
  133.         ObjectNode= ObjectNode->NextObject;  
  134.       } // End while
  135.     return Count;              
  136.   } // End of CheckCollision for G3DWORLD                                
  137.   
  138.